import 'package:flutter/material.dart';
import 'package:flutter_demo_k/page/stream_builder_test.dart';

class RepaintBoundaryTest extends StatelessWidget {
  static const String routeName = '/repaint_boundary_test';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('RepaintBoundary Example'),
      ),
      body: Center(
        child: Column(
          children: [
            // 使用 RepaintBoundary 包裹需要隔离的子树
            RepaintBoundary(
              child: CustomPaint(
                painter: MyPainter(),
                child: const SizedBox(
                  width: 200,
                  height: 200,
                ),
              ),
            ),
            // 其他组件
            // Container(
            //   width: 100,
            //   height: 100,
            //   color: Colors.blue,
            // ),
          ],
        ),
      ),
    );
  }
}

class MyPainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    final paint = Paint()
      ..color = Colors.red
      ..strokeWidth = 4.0
      ..style = PaintingStyle.stroke;

    canvas.drawRect(Rect.fromLTWH(0, 0, size.width, size.height), paint);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return false;
  }
}
